package org.truenewx.tnxjee.repo.mybatis;

import java.io.Serializable;

import org.truenewx.tnxjee.core.util.ClassUtil;
import org.truenewx.tnxjee.model.entity.Entity;
import org.truenewx.tnxjee.model.entity.unity.Unity;
import org.truenewx.tnxjee.repo.mybatis.mapper.EntityMapper;
import org.truenewx.tnxjee.repo.mybatis.mapper.UnityMapper;

public class MyBatisUnityMapperRepository<T extends Unity<K>, K extends Serializable> extends
        MyBatisEntityMapperRepository<T, K> {

    private final UnityMapper<T, K> mapper;

    public MyBatisUnityMapperRepository(UnityMapper<T, K> mapper) {
        this.mapper = mapper;
    }

    @Override
    protected EntityMapper<T> getMapper() {
        return this.mapper;
    }

    @Override
    public Class<? extends Entity> getEntityClass() {
        return ClassUtil.getActualGenericType(this.mapper.getClass(), UnityMapper.class, 0);
    }

    @Override
    public boolean existsById(K id) {
        return this.mapper.existsById(id);
    }

}
